#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os.path
import thread, threading
import gtk
import math

import clutter

from thumbnailer import Thumbnailer

class PhotoFlip:
    def __init__(self):
        self.stage = clutter.Stage()
        self.stage.set_title("PhotoFlip 0.3svn")
        self.stage.set_size(1024, 768)
        self.stage.set_color(clutter.Color(0x00, 0x00, 0x00, 0xff))

        self.photos_list = []
        
        self.photo_x = 350
        self.photo_y = 450

        self.load_photos()

    def load_photos(self):
        self.loading_photo = gtk.gdk.pixbuf_new_from_file(os.path.join('share', 'gfx', 'loading_photo.jpg'))

        for filename in os.listdir('library'):
            if filename[0] == '.': continue
            texture = clutter.Texture(self.loading_photo)
            self.photos_list.append((texture,filename))


        angle = 3.141592654 * 2 / len(self.photos_list)

        i = 0
        print len(self.photos_list)
        while i < len(self.photos_list):
            self.photos_list[i][0].set_position(self.photo_x + int(math.sin(i * angle) * 200), self.photo_y)
            self.photos_list[i][0].set_depth(int((math.cos(i * angle)) * 200))
            self.photos_list[i][0].set_size(300, 200)

            self.photos_list[i][0].show()
            self.stage.add(self.photos_list[i][0])
            i += 1

        self.thumbnailer = Thumbnailer()
        self.thumbnailer.start()
            
    '''def create_media(self, filename, x, y):
        media = cluttergst.VideoTexture()
        media.set_filename(filename)
        media.set_position(x, y)

        media.set_playing(True)
        media.set_size(320, 240)
        media.show()
        self.stage.add(media)'''

    def run(self):
        self.stage.show_all()
        clutter.main()

def main (args):
    app = PhotoFlip()
    app.run()
    return 0

if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))
